package org.jackysoft.struts2.myapp;
import java.io.ByteArrayInputStream;
import java.util.Collection;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Namespace;
import org.jackysoft.entity.Journal;
import org.jackysoft.service.JournalService;
import org.jackysoft.struts2.UtilsCRUDAction;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;



@Namespace("/journal")
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class JournalAction extends UtilsCRUDAction<Journal> {
	/**
	 * 
	 */
	private static final long serialVersionUID = -6228714019237543330L;
	private JournalService service;
	private Journal bean;
	private Collection<Journal> beans;	
	
	
	public String load() throws Exception{
		
		bean = service.create(bean.getCreateDate());
	    return "get";
		
	}	
	
	public String loadcontent() throws Exception{
		bean = service.get(bean.getId());
		byte[] data = bean.getData();
		contentLength = data.length;
		upLoadFileName= "journal.xls";
		inputStream = new ByteArrayInputStream(data);
		return STREAM;
	}
	
	
	public String savecontent() throws Exception{
		service.update(bean);
		return "saveok";
	}
	
	
	
	public void setBean(Journal bean){
	     this.bean = bean;
	}
	public Journal getBean(){
	     return this.bean;
	}
	public void setBeans(Collection<Journal> beans){
	
	     this.beans = beans;
	}
	public Collection<Journal> getBeans(){
	     return this.beans;
	}
	
	@Resource
	public void setService(JournalService service) {
		this.service = service;
		this.setDataProvider(service);
	}	
	
	public JournalService getService(){
	   return this.service;
	}
		
}